package com.inspectortime.webapp.inspector;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;

import com.inspectortime.domain.Inspector;
import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.util.SpringValidatorUtils;
import com.inspectortime.webapp.util.HttpSessionUtils;

/**
 * Add a new Inspector to an existing company
 * 
 * @author bones
 *
 */
public class AddInspectorController extends AddEmployeeController {
	
	private static Log log = LogFactory.getLog(AddInspectorController.class);
	protected void onBindAndValidate(HttpServletRequest request,
			Object command, BindException errors) throws Exception {
		SpringValidatorUtils.logValidationErrors(log, errors);
	}

	protected Map referenceData(HttpServletRequest request) throws Exception {
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("add", new Boolean(true));
		return data;
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {		
		InspectorCompany company = HttpSessionUtils.retrieveLoggedInCompany(request, repository);
		Inspector newInspector = factory.createInspector(company);
		return newInspector;
	}
	
	
}
